import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.Properties;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Fxjewellry$SettingsManager
{
  private String name;
  private LinkedList<Fxjewellry.SettingsManager.Pair> pairs = new LinkedList();

  public Fxjewellry$SettingsManager(Fxjewellry paramFxjewellry, String paramString) {
    this.name = paramString;
  }

  public void add(String paramString, JComponent paramJComponent) {
    this.pairs.add(new Fxjewellry.SettingsManager.Pair(this, paramString, paramJComponent));
  }

  public void load() {
    try {
      File localFile = new File(this.name);
      if (!localFile.exists()) {
        return;
      }
      FileReader localFileReader = new FileReader(localFile);
      Properties localProperties = new Properties();
      localProperties.load(localFileReader);
      for (Fxjewellry.SettingsManager.Pair localPair : this.pairs) {
        String str = localProperties.getProperty(localPair.key);
        if (str == null) {
          continue;
        }
        if ((localPair.component instanceof JComboBox)) {
          ((JComboBox)localPair.component).setSelectedItem(str);
        }
        else if ((localPair.component instanceof JCheckBox)) {
          ((JCheckBox)localPair.component).setSelected(Boolean.parseBoolean(str));
        }
        else if ((localPair.component instanceof JTextField))
          ((JTextField)localPair.component).setText(str);
        else if ((localPair.component instanceof JTextArea)) {
          ((JTextArea)localPair.component).setText(str);
        }
      }
      localFileReader.close();
    } catch (Exception localException) {
      localException.printStackTrace();
    }
  }

  public void save() {
    try {
      File localFile = new File(this.name);
      FileWriter localFileWriter = new FileWriter(localFile);
      Properties localProperties = new Properties();
      for (Fxjewellry.SettingsManager.Pair localPair : this.pairs) {
        String str = "null";
        if ((localPair.component instanceof JComboBox)) {
          str = (String)((JComboBox)localPair.component).getSelectedItem();
        }
        else if ((localPair.component instanceof JCheckBox)) {
          str = Boolean.toString(((JCheckBox)localPair.component).isSelected());
        }
        else if ((localPair.component instanceof JTextField))
          str = ((JTextField)localPair.component).getText();
        else if ((localPair.component instanceof JTextArea)) {
          str = ((JTextArea)localPair.component).getText();
        }
        localProperties.setProperty(localPair.key, str);
      }
      localProperties.store(localFileWriter, "SettingsManager by NoEffex");
      localFileWriter.close();
    } catch (Exception localException) {
      localException.printStackTrace();
    }
  }
}